//
//  WaterflowerViewCell.m
//  TTWaterFlower
//
//  Created by 田涛 on 2017/3/14.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "WaterflowerViewCell.h"
#import "TTWaterflowerView.h"
#import "Model.h"
#import "SDWebImage/UIImageView+WebCache.h"

@interface WaterflowerViewCell ()
@property (nonatomic, weak) UIImageView *imgView;
@property (nonatomic, weak) UILabel *priceLbl;
@end

@implementation WaterflowerViewCell

+ (instancetype)cellWithWaterflowerView:(TTWaterflowerView *)waterflowerView {
    
    static NSString *cellID = @"waterflowerCell";
    WaterflowerViewCell *cell = [waterflowerView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[WaterflowerViewCell alloc] init];
        cell.identifier = cellID;
    }
    return cell;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        UIImageView *imgView = [[UIImageView alloc] init];
        [self addSubview:imgView];
        self.imgView = imgView;
        
        UILabel *priceLbl = [[UILabel alloc] init];
        priceLbl.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        priceLbl.textAlignment = NSTextAlignmentCenter;
        priceLbl.textColor = [UIColor whiteColor];
        [self addSubview:priceLbl];
        self.priceLbl = priceLbl;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imgView.frame = self.bounds;
    self.priceLbl.frame = CGRectMake(0, self.bounds.size.height - 20, self.bounds.size.width, 20);
}

- (void)setModel:(Model *)model {
    _model = model;
    self.priceLbl.text = model.price;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
}

@end
